using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.IO;

namespace GotLyrics
{
    public class AudioFileContext : LyricGrabberContext
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AudioFileContext"/> class.
        /// </summary>
        /// <param name="listViewItem">The list view item.</param>
        /// <param name="filename">The filename.</param>
        public AudioFileContext(ListViewItem listViewItem, string filename) : base(filename) 
        {
            if (listViewItem == null)
                throw (new ArgumentNullException("listViewItem"));

            if (listViewItem.ListView == null)
                throw (new Exception("ListViewItem is not a member of a ListView"));

            _listViewItem = listViewItem;

            ReflectListViewItem();
        }

        private bool _isModified;
        /// <summary>
        /// Gets or sets a value indicating whether this instance is modified.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is modified; otherwise, <c>false</c>.
        /// </value>
        public bool IsModified
        {
            get { return _isModified; }
            set { _isModified = value; }
        }

        private ListViewItem _listViewItem;
        /// <summary>
        /// Gets the list view item.
        /// </summary>
        /// <value>The list view item.</value>
        public ListViewItem ListViewItem
        {
            get { return _listViewItem; }
        }

        /// <summary>
        /// Reflects the list view item.
        /// </summary>
        public void ReflectListViewItem()
        {
            ListViewItem.SubItems.Clear();

            ListViewItem.Text = Path.GetFileName(Filename);
            ListViewItem.Tag = this;
            ListViewItem.Name = Filename;

            ListViewItem.SubItems.Add(Tags.Artist);
            ListViewItem.SubItems.Add(Tags.Album);
            ListViewItem.SubItems.Add(Tags.Title);
            ListViewItem.SubItems.Add(Tags.TrackNum.ToString());

            if (_isModified)
                ListViewItem.Font = GetModifiedFileFont(ListViewItem.ListView);
            else
                ListViewItem.Font = ListViewItem.ListView.Font;
        }

        private static Font _modifiedFilesFont;
        private static Font GetModifiedFileFont(ListView listView)
        {
            if (_modifiedFilesFont == null)
                _modifiedFilesFont = new Font(listView.Font, listView.Font.Style | FontStyle.Bold);

            return _modifiedFilesFont;
        }
    }
}
